/**
 * Created by Administrator on 2018/1/25 0025.
 */
/**
 *克隆复制检查部位
 * *
 * */

$(function(){
    $(document).on("click",".add_jilu .list_box .li_s .new_list span.option_btn",function(){

        $('.new_list').each(function(i){
            var i = i+2;
            $("[name='patient_part_lat["+i+"][part]']").remove();
            $("[name='patient_part_lat["+i+"][lat]']").remove();
        })

        $(this).parent().parent().remove();
        reset_data();
    });
    $(document).on("click",".add_jilu .list_box .msg li .top .li_1 div.add_box span.option_btn",function(){
    var new_list = $(".add_jilu .right_box .top .li_1 ").clone();
    new_list.addClass("new_list");
    new_list.addClass("top");
    $(".add_jilu ul .li_s").append(new_list);
    reset_data();
    });
    })

$(function(){


    $(document).on("mouseenter",".new_huanzhe_record .list_box .list .pic_dec",function(){
        $(this).find("em").show();
    });
    $(document).on("mouseleave",".new_huanzhe_record .list_box .list .pic_dec",function(){
        $(this).find("em").hide();
    });
})

$(function(){
    // 点击删除的字  删除的的 垃圾箱 按钮 显示
    $(document).on("click",".data_2 .tit_top .tit_right a.cancle_btn",function(){

        var length = $(".pic_box").length;
        console.log(length);
        if(length == 1) {
            layer.msg("至少一个分组");
            $(".new_huanzhe_record em.decrease_btn").css({"display":"none"});
        }else{
            $(".new_huanzhe_record em.decrease_btn").css({"display":"inline-block"});
        }
        });
    // 点击 垃圾箱   添加进去的 盒子  消失
    $(document).on("click",".new_huanzhe_record em.decrease_btn",function(){
        console.log($(this).parent());
        $(this).parent().remove();
        var length = $(".pic_box").length;
        console.log(length);
        if(length == 1){

            $(".new_huanzhe_record em.decrease_btn").css({"display":"none"});
        }



    })
    })


$(".content").on("change",".change_lat",function(){
    var change_val = $(this).val();
    console.log(change_val);
    $(this).parents(".top").find(".patient_lat").val(change_val);


})
$(".content").on("change",".change_part",function(){
    var change_val = $(this).val();

    $(this).parents(".top ").find(".patient_part").val(change_val);

})


/* 重新给name和id序列号  */
function reset_data(){
    var length = $('.new_list').length;
    var add_box_num = length+1;
    $("[name=add_case_depart_lat]").val(add_box_num);
    console.log(add_box_num);
    var default_lat = $("[name=default_lat]").val();
    var default_part = $("[name=default_part]").val();
    if(length > 0 ){

        $('.new_list').each(function(i){

            i = i+2;
            console.log(add_box_num);

            /* <input type="hidden" name="patient_part_lat[1]['part']" value="{isset($case_lat[0]['id']) ? $case_lat[0]['id'] : ''}">
             <input type="hidden" name="patient_part_lat[1]['lat']" value="{isset($case_depart[0]['id']) ?$case_depart[0]['id'] : '' }">
             */
            if($("[name='patient_part_lat["+i+"][part]']").length){
                //  console.log('ss');
            }else{
                //console.log('vvvvv');
                var html_part = '<input type="hidden" class="patient_lat" name="patient_part_lat['+i+'][lat]" value="'+default_lat+'">' ;
                html_part += '<input type="hidden" class="patient_part"  name="patient_part_lat['+i+'][part]" value="'+default_part+'">' ;
                $(this).append(html_part);
            }
        })
    }

}

/**初始化加载DCM
 * **/
var app_i = 0;
function init_dicom(n,k,url){
    // base function to get elements
    console.log(url);

    dwv.gui.getElement = dwv.gui.base.getElement;
    dwv.gui.displayProgress = function (percent) {};
	var app = [];

    // create the dwv app
    app[app_i] = new dwv.App();
    var urls = url.split(",")
    
	app[app_i].loadURLs(urls);
    // initialise with the id of the container div
    app[app_i].init({
        "containerDivId": "dwv_"+n+"_"+k
    });

    // load dicom data
    //读取electronic_report_1数组中的值,换成数组,加载dcm文件
    
    app_i++;
}


/* dcm点击查看 */
function layerDcm(n,k,dcmUrl){
    dcmUrl = dcmUrl.split(",");
    var html = '<div id="dwv_'+n+'s_'+k+'s"><div class="layerContainer"><canvas class="imageLayer"></canvas>' ;
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        area:  ['500px','500px'],
        skin: 'bgLayer', //没有背景色
        shadeClose: true,
        content: html,
        success: function(layero, index){
            init_dicom(n+"s",k+"s",url);
        }
    });

}
/* 图片点击查看 */
function layerDcm2(thiss){



var img_url = $(thiss).find('img').attr("src");
    console.log(img_url);

// 创建对象
    var img = new Image();
// 改变图片的src
    img.src = img_url;

   var w = img.width;

    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        area:  "'+w+'",
        offset: 'auto',
        skin: 'bgLayer', //没有背景色
        shadeClose: true,
        content: $(thiss).html(),
    });
}




